package com.zfk.transaction.controller;


import com.zfk.transaction.entity.chat.ChatContent;
import com.zfk.transaction.entity.chat.ChatSeller;
import com.zfk.transaction.service.ChatService;
import com.zfk.transaction.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chat")
@Api("ChatController")
public class ChatController {


    @Autowired
    private ChatService service;

    // 显示用户的与商家聊天列表
    @GetMapping("/getChatSellers")
    @ApiOperation("getChatSellers")
    public Response getChatSellers(@RequestParam int user_id){

        List<ChatSeller> list = service.getChatByUserId(user_id);
        list.stream().forEach(System.out::println);
        return Response.ok(list);
    }

    // 删除用户与某个商家的聊天
    @GetMapping("/deleteChatSeller")
    @ApiOperation("deleteChatSeller")
    public Response deleteChatSeller(@RequestParam int id){

        service.deleteChatSeller(id);

        return Response.ok();
    }

    // 得到用户与某个商家的聊天记录
    @GetMapping("/getChatContent")
    @ApiOperation("getChatContent")
    public Response getChatContent(@RequestParam int user_id,
                                   @RequestParam int seller_id){
        System.out.println("user_id : "+user_id + " ====  seller_id = " + seller_id);
        List<ChatContent> chatMessage = service.getChatMessage(user_id, seller_id);
        return Response.ok(chatMessage);
    }

    // 增加聊天信息
    @PostMapping("/addChatContent")
    @ApiOperation("addChatContent")
    public Response addChatContent(@RequestParam ChatContent chatContent){

        service.addChatContent(chatContent);

        return Response.ok();
    }

    // 增加用户与商人聊天
    @PostMapping("/addChatSeller")
    @ApiOperation("addChatSeller")
    public Response addChatSeller(@RequestParam ChatSeller chatSeller){

        service.addChatSeller(chatSeller);

        return Response.ok();
    }


}
